import 'package:flutter/material.dart';
import 'package:xview/components/xCell.dart';
import 'package:xview/components/xNavbar.dart';
import 'package:xview/utils/dimension.dart';

class home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _homeState();
  }
}

class _homeState extends State<home> {
  @override
  Widget build(BuildContext context) {

    List<dynamic> data = [
      {'title':'基础组件','list':[
        {'title':'按钮','path':'/button'},
      ]},
      {'title':'导航组件','list':[
        {'title':'自定义导航栏','path':'/navbar'},
      ]},
      {'title':'布局组件','list':[
        {'title':'tabs标签','path':'/tabs'},
        {'title':'swiper轮播','path':'/swiper'},
        {'title':'tabswiper滑动选项卡','path':'/tabsSwiper'},
      ]},
      {'title':'反馈组件','list':[
        {'title':'下拉菜单','path':'/dropDown'},
        {'title':'加载更多','path':'/loadMore'},
      ]},
    ];

    return Scaffold(
      appBar: XNavbar(
        isBack: false,
        title: 'XView',
      ).render(context),
      body: Container(
        child: Column(
          children: [
            Expanded(
              flex: 1,
              child: ListView.builder(
                itemCount: data.length,
                itemBuilder: (context,index){
                  return itemView('${data[index]['title']}',data[index]['list']);
                },
              ),
            )
          ],
        ),
      ),
    );
  }

  itemView(title,list){
    List<Widget> arr = [];
    int loop = 0;
    for(var item in list){
      arr.add(XCell(
        title: '${item['title']}',
        path: '${item['path']}',
        borderBottomWidth: loop+1==list.length?0:1,
      ));
      loop++;
    }

    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            padding: EdgeInsets.symmetric(vertical: Dimension(context).toPx(10),horizontal: Dimension(context).toPx(15)),
            child: Text('${title}',style: TextStyle(color: Color(0xff909193),fontSize: Dimension(context).toPx(15))),
          ),
          Column(
            children: arr,
          )
        ],
      ),
    );
  }
}
